/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package algoritmo;

/**
 *
 * @author melvinrafaelvegavega
 */
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.lang.*;
import java.util.*;
import java.text.*;

import javax.swing.*;
import javax.swing.event.*;

public class StatusBarInfo extends JFrame
{
	JTextField messageField;
	JTextField userField;
	JTextField dateLongField;
	JTextField capsLockField;
	JTextField numLockField;
	JTextField scrollLockField;
	JTextField timeField;
	static boolean capsBoolean = false;
	static boolean numBoolean  = false;
	static boolean scrollBoolean = false;
	JTextPane jtextpane;

	public StatusBarInfo()
	{
		setTitle("Status Bar Demo");
		setBounds(100, 80, 600, 400);

		Container contentPane = getContentPane();

		//StatusBar
		Box sbar = Box.createHorizontalBox();
		messageField = new JTextField(30);
		messageField.setBackground(Color.LIGHT_GRAY);

		userField = new JTextField(12);
		userField.setBackground(Color.LIGHT_GRAY);

		dateLongField = new JTextField(18);
		dateLongField.setText(showTodayDate());
		dateLongField.setBackground(Color.LIGHT_GRAY);

		capsLockField = new JTextField(5);
		capsLockField.setBackground(Color.LIGHT_GRAY);
		capsLockField.setText("Caps");
		capsBoolean = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
		getCapsStatus();

		numLockField = new JTextField(5);
		numLockField.setText("Num");
		numLockField.setBackground(Color.LIGHT_GRAY);
		//numBoolean = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_NUM_LOCK);
		getNumStatus();

		scrollLockField = new JTextField(5);
		scrollLockField.setText("Scroll");
		scrollLockField.setBackground(Color.LIGHT_GRAY);
		//scrollBoolean = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_SCROLL_LOCK);
		getScrollStatus();

		timeField = new JTextField(5);
		timeField.setBackground(Color.LIGHT_GRAY);
		showSysTime(timeField);

		jtextpane = new JTextPane();

		sbar.add(messageField);
		sbar.add(Box.createGlue());
		sbar.add(userField);
		sbar.add(dateLongField);
		sbar.add(capsLockField);
		sbar.add(numLockField);
		sbar.add(scrollLockField);
		sbar.add(timeField);
		sbar.add(timeField);

		contentPane.add(jtextpane, BorderLayout.CENTER);
		contentPane.add(sbar, BorderLayout.SOUTH);
		jtextpane.addKeyListener(new KeyAdapter()
		{
			public void keyReleased(KeyEvent ke)
			{
				if(ke.getKeyCode() == KeyEvent.VK_CAPS_LOCK)
				{
					capsBoolean = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
					getCapsStatus();
				}
				if(ke.getKeyCode() == KeyEvent.VK_NUM_LOCK)
				{
					numBoolean = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_NUM_LOCK);
					getNumStatus();
				}
				if(ke.getKeyCode() == KeyEvent.VK_SCROLL_LOCK)
				{
					scrollBoolean = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_SCROLL_LOCK);
					getScrollStatus();
				}

			}
		});

		capsLockField.addMouseListener(new MouseAdapter()
		{
			public void mouseReleased(MouseEvent me)
			{
				if(me.getClickCount() == 2)
				{
					if(capsBoolean == true)
						capsBoolean = false;
					if(capsBoolean == false)
						capsBoolean = true;
					getCapsStatus();
				}

			}
		});

		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setVisible(true);
	}

	public static void main(String[] args)
	{
		StatusBarInfo mf = new StatusBarInfo();
	}

	public void getCapsStatus()
	{
		if(capsBoolean == true)
			capsLockField.setEnabled(true);
		if(capsBoolean == false)
			capsLockField.setEnabled(false);
	}
	public void getNumStatus()
	{
		if(numBoolean == true)
			numLockField.setEnabled(true);
		if(numBoolean == false)
			numLockField.setEnabled(false);
	}
	public void getScrollStatus()
	{
		if(scrollBoolean == true)
			scrollLockField.setEnabled(true);
		if(scrollBoolean == false)
			scrollLockField.setEnabled(false);
	}
	public String showTodayDate()
	{
		Date dt = new Date();
		System.out.println(dt.toString());
		SimpleDateFormat sdf = new SimpleDateFormat("EEE, MMM d, ''yy");
		return sdf.format(dt).toString();
	}
	public void showSysTime(final JTextField tf)
	{
	 	final SimpleDateFormat timef = new SimpleDateFormat("HH:mm");
		javax.swing.Timer timer = new javax.swing.Timer(1000, new ActionListener()
		{
		  public void actionPerformed(ActionEvent e)
		  {
			String s = timef.format(new Date(System.currentTimeMillis()));
			tf.setText(s);
		  }
		});
		timer.start();
	}

}